package com.geen.tuoke.bean

import androidx.databinding.BaseObservable
import androidx.databinding.Bindable
import com.blankj.utilcode.util.LogUtils
import com.geen.tuoke.utils.Arith
import com.geen.tuoke.utils.DateUtils
import java.io.Serializable
import java.math.BigDecimal

/**
 * @Author LuoJi
 * @Date 2022/1/17-17:42
 * @Desc 拨号界面任务列表
 */
data class TaskInfo(
    val id: Int,
    //已拨打数量
    var calloutCount: Int,
    //任务完成状态 0 未完成，1 表示完成
    val finishStatus: Int,
    // 任务创建时间
    val createTime: Long,
    //意向数量
    var intentionCount: Int,
    //是否是手动添加任务:0 非人工添加 1人工添加
    val manAddTask: String,
    val name: String,
    //任务电话总数量
    var phoneCount: Int,
    //接通数量
    var switchOnCount: Int,
    //任务间隔时间
    val intervalTime: Int
) : Serializable, BaseObservable() {


    fun getRate(): String {
        if (switchOnCount == 0) {
            return "0%"
        }
        return Arith.div(phoneCount.toDouble(), switchOnCount.toDouble(), 0).toString() + "%"
    }

    fun getTimeStr(): String {
        return DateUtils.formatCreateTime(createTime)
    }

    fun getCallText(): String {

        return "$calloutCount/$phoneCount"
    }


    /**任务详情页面专用*/

    fun getCallNoText(): String {
        val waitCount = phoneCount - calloutCount
        val percent = div(waitCount, phoneCount)
        return "待拨打：  ${waitCount}  ${percent}"
    }

    fun getCallYesText(): String {
        val percent = div(calloutCount, phoneCount)
        return "已拨打：  ${calloutCount}  ${percent}"
    }

    fun getConnectYesText(): String {
        val percent = div(switchOnCount, phoneCount)
        return "接通：  ${switchOnCount}  ${percent}"
    }

    fun getIntentionText(): String {
        val percent = div(intentionCount, phoneCount)
        return "意向：  ${intentionCount}  ${percent}"
    }

    fun div(smallNum: Int, bigNum: Int): String {
        try {
            return "${(Arith.div(smallNum.toDouble() , bigNum.toDouble() , 2) * 100).toInt()}%"
        } catch (e: Exception) {
        }
        return "0%"
    }

}